import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { UserForm, UserInfo, UserPageVO, UserQuery } from "./types";
import { loginLog, loginLogQuery } from "../loginLog/types";
import { operateLog, operateLogQuery } from "../operateLog/types";

/**
 * 登录成功后获取用户信息（昵称、头像、权限集合和角色集合）
 */
export function getUserInfoApi(): AxiosPromise<UserInfo> {
  return request({
    url: "/admin/user/info",
    method: "get",
  });
}

/**
 * 获取用户分页列表
 *
 * @param queryParams
 */
export function getUserPage(
  queryParams: UserQuery
): AxiosPromise<PageResult<UserPageVO[]>> {
  return request({
    url: "/admin/user/index",
    method: "get",
    params: queryParams,
  });
}

/**
 * 获取用户表单详情
 *
 * @param ids
 */
export function getUserForm(ids: number): AxiosPromise<UserForm> {
  return request({
    url: "/admin/user/edit",
    method: "get",
    params: {
      ids: ids,
    },
  });
}

/**
 * 添加用户
 *
 * @param data
 */
export function addUser(data: any) {
  return request({
    url: "/admin/user/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改用户
 *
 * @param id
 * @param data
 */
export function updateUser(data: UserForm) {
  return request({
    url: "/admin/user/edit",
    method: "put",
    data: data,
  });
}

export function modify(data: any) {
  return request({
    url: "/admin/user/modify",
    method: "put",
    data: data,
  });
}

/**
 * 修改用户密码
 *
 * @param id
 * @param password
 */
export function updateUserPassword(id: number, password: string) {
  return request({
    url: "/admin/user/resetPassword",
    method: "put",
    data: { ids: id, password: password },
  });
}

/**
 * 删除用户
 *
 * @param data
 */
export function deleteUsers(data: any) {
  return request({
    url: "/admin/user/del",
    method: "delete",
    data,
  });
}

export function loginLogLst(
  queryParams: loginLogQuery
): AxiosPromise<PageResult<loginLog[]>> {
  return request({
    url: "/admin/user/loginLog",
    method: "get",
    params: queryParams,
  });
}

export function operateLogLst(
  queryParams: operateLogQuery
): AxiosPromise<PageResult<operateLog[]>> {
  return request({
    url: "/admin/user/operateLog",
    method: "get",
    params: queryParams,
  });
}
